<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<table>
		<div id="map" style="width:600px;height:450px;"></div>
		<tr>
			<td>地址:</td>
			<td><input type="text" name="ad_name" id="ad_name"></td>
		</tr>
		<tr>
			<td><button id="search">搜索</button><button id="rk">当前位置入库</button></td>
		</tr>
	</table>
</body>
</html>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=Xxo1E9gVz0wV6ngWRyz3GGcRN0BYqzIS"></script>
<script>
    var lng,lat;
   // 百度地图API功能
	var map = new BMap.Map("map");
	var point = new BMap.Point(116.331398,39.897445);
	map.centerAndZoom(point,18);

	var geolocation = new BMap.Geolocation();
	geolocation.getCurrentPosition(function(r){
		if(this.getStatus() == BMAP_STATUS_SUCCESS){
			var mk = new BMap.Marker(r.point);
			map.addOverlay(mk);
			map.panTo(r.point);
			alert('您的位置：'+r.point.lng+','+r.point.lat);
			lng=r.point.lng;
			lat=r.point.lat;
		}
		else {
			alert('failed'+this.getStatus());
		}        
	},{enableHighAccuracy: true})
	//当前位置入库
	 $(document).on("click","#rk",function(){
			$.ajax({
			   	  	url:"{url:/dt/map}",
			   	  	type:"post",
			   	  	dataType:"json",
			   	  	data:{lng:lng,lat:lat},
			   	  	success:function(res)
			   	  	{
			          if(res==1)
			          {
			          	alert("入库成功");
			          }
			   	  	}
			 })
	     })
	   	//搜索的关键字
   $(document).on("click","#search",function(){
      
   	  //接值
   	  var ad_name=$("#ad_name").val();
      	// 百度地图API功能
	var map = new BMap.Map("map");            // 创建Map实例
	var mPoint = new BMap.Point(lng, lat);  
	map.enableScrollWheelZoom();
	map.centerAndZoom(mPoint,15);

	var circle = new BMap.Circle(mPoint,3000,{fillColor:"blue", strokeWeight: 1 ,fillOpacity: 0.3, strokeOpacity: 0.3});
    map.addOverlay(circle);
    var local =  new BMap.LocalSearch(map, {renderOptions: {map: map, autoViewport: false}});  
    local.searchNearby(ad_name,mPoint,3000);
   })
</script>